// pages/xiaoxi/shenpi/detail/index.js

const myRequest = require("../../../../utils/require.js")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: '',
    id:'',
    detail:'',
    showModal:'',
    code:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    app.CheckSession().then(res => {
      if (res == true) {
        app.GetUser().then(data => {
          this.setData({
            userInfo: data,
            id:options.id,
            code:options.code
          })
          //请求详情
          let id=   options.id  
           this.ApiRequest(id)  
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  ApiRequest(id){
    
    myRequest.myRequest('DisSource/shenhe/'+id,{code:this.data.code},'GET').then(
      res=>{
        console.log(res)
        if(res.code=='success'){
          this.setData({
            detail:res.data
          })
        }
      }
    );
  },
  /**
   * 返回
   */
  Back(e){

    app.BackUpdate()
    wx.navigateBack({
      delta: 1,
    })
  },
  Xiugai(e){
 
      wx.navigateTo({
        url: '/pages/fabu/index?id=' + this.data.detail.workshop.id + '&code=' + this.data.detail.code,
      })
    
   
  },
  Chongxin(e) {

    myRequest.myRequest('DisSource/apply/' + this.data.detail.workshop.id, { code: this.data.detail.code }, 'POST').then(res => {
      app.BackUpdate()
      wx.showToast({
        title: res.message,
        success: res => {
          this.ApiRequest(this.data.id)
        },
        fail: function (res) { },
        complete: function (res) { },
      })

    })
  },
  /**
   * 
   * 修改内容重新申请
   */
  /**
  * 审核通过
  */
  Tongyi(e) {
    console.log(e)
    let id = this.data.detail.id
    wx.showModal({
      title: '确定同意审核么?',
      content: '',
      showCancel: true,
      cancelText: '取消',
      cancelColor: '',
      confirmText: '确定',
      confirmColor: '',
      success: res => {
        if (res.confirm) {
          app.BackUpdate()
          myRequest.myRequest('DisSource/shenhe/' + id, {}, 'POST').then(data => {
            console.log(data)
            if (data.code == "success") {
                this.ApiRequest(id)
            }
          }
          )
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })

  },
  /**
 * 驳回
 */
  Bohui(e) {
    
    this.setData({
      showModal: '1',
    })
  },
  CancelBohui(e) {
    this.setData({
      showModal: null,
      
    })
  },
  SureBohui(e) {
    console.log(e.detail.value.refuse)
    myRequest.myRequest('DisSource/refuse/' + this.data.detail.id, { refuse: e.detail.value.refuse }, 'POST').then(
      res => {
        if (res.code == "success") {
          app.BackUpdate()
          this.ApiRequest(this.data.detail.id) 
          this.setData({
            showModal: null,
          })
        } else {
          wx.showToast({
            title: res.message,
            icon: '',
            image: '',
            duration: 0,
            mask: true,
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
          })
        }
      }
    )
  }
})